package com.mall.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.CmsSubjectMapper;
import com.mall.model.domain.CmsSubject;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【cms_subject(专题表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class CmsSubjectApiImpl extends ServiceImpl<CmsSubjectMapper, CmsSubject>
        implements CmsSubjectApi {

    @Autowired
    private CmsSubjectMapper subjectMapper;

    @Override
    public List<CmsSubject> findAll() {

        LambdaQueryWrapper<CmsSubject> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNotNull(CmsSubject::getId);

        List<CmsSubject> subjects = subjectMapper.selectList(queryWrapper);
        return subjects;
    }

    @Override
    public Page<CmsSubject> listPage(Integer pageNum, Integer pageSize, String keyword) {

        LambdaQueryWrapper<CmsSubject> lqw = new LambdaQueryWrapper<>();
        lqw.like(StringUtils.isNotEmpty(keyword), CmsSubject::getCategoryName, keyword);

        Page<CmsSubject> page = new Page<>(pageNum, pageSize);

        return subjectMapper.selectPage(page, lqw);
    }

}




